<template>
	<view class="acttention" :class="theme() || ''" :data-theme='theme()'>
		<scroll-view scroll-y="true" :style="'height:' + scrollviewHigh + 'px;'" class="scroll-Y" lower-threshold="50"
			@scrolltolower="scrolltolowerFunc">
			<view class="acttention-item" v-for="(item,index) in product_list" :key="index">
				<image class="item-image" :src="item.product_image" @click="goto_product(item.product_id)" />
				<view class="item-info" @click="goto_product(item.product_id)">
					<view class="item-title f28 gray3">{{item.product_name}}</view>
					<view class="item-price">
						<view class="f24 theme-price">¥<text class="f36 fb">{{item.product_price}}</text></view>
						<view class="f24 huaxianjia flex-1">¥<text class="">{{item.line_price}}</text></view>
						<button class="theme-btn item-btn " @click="guanzhu(item.product_id)">取消收藏</button>
					</view>
				</view>
			</view>
			<view class="d-c-c p30" v-if="product_list.length==0 && !loading">
				<text class="iconfont icon-wushuju"></text>
				<text class="cont">亲，暂无相关记录哦</text>
			</view>
			<uni-load-more v-else :loadingType="loadingType"></uni-load-more>
		</scroll-view>
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more.vue";
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				/*底部加载*/
				loading: true,
				/*没有更多*/
				no_more: false,
				//页面高度
				scrollviewHigh: '',
				//商品列表
				product_list: [],
				//当前页
				page: 1,
				//总页数
				last_page: '',
				isfollow: '',
			}
		},
		computed: {
			/*加载中状态*/
			loadingType() {
				if (this.loading) {
					return 1;
				} else {
					if (this.product_list.length != 0 && this.no_more) {
						return 2;
					} else {
						return 0;
					}
				}
			}
		},
		onShow() {
			this.init();
			this.getData();
		},
		methods: {
			/*初始化*/
			init() {
				let self = this;
				self.page = 1;
				self.product_list = [];
				uni.getSystemInfo({
					success(res) {
						self.scrollviewHigh = res.windowHeight;
					}
				});
			},
			//获取数据
			getData() {
				let self = this;
				self.loading = true;
				self._post('user.Favorite/list', {
					page: self.page,
					type: 20,
					list_rows: 15,
				}, (res) => {
					self.loading = false;
					self.last_page = res.data.list.last_page;
					self.product_list = self.product_list.concat(res.data.list.data);
					if (res.data.list.last_page <= 1) {
						self.no_more = true;
					} else {
						self.no_more = false;
					}
				})

			},
			/*可滚动视图区域到底触发*/
			scrolltolowerFunc() {
				let self = this;
				if (self.no_more) {
					return;
				}
				self.page++;
				if (self.page <= self.last_page) {
					self.getData();
				} else {
					self.no_more = true;
				}
			},
			goto_product(e) {
				this.gotoPage('pages/product/detail/detail?product_id=' + e);
			},
			//关注商户/取消关注
			guanzhu(product_id) {
				let self = this;
				self.page = 1
				self.loading = true;
				self._post('user.Favorite/add', {
					pid: product_id,
					type: 20,
				}, (res) => {
					self.loading = false;
					self._post('user.Favorite/list', {
						page: self.page,
						type: 20,
						list_rows: 15,
					}, (res) => {
						self.product_list = res.data.list.data;

					})
				})
			},
		}
	}
</script>

<style>
	page {
		background-color: #f2f2f2;
	}

	.h1 {
		font-size: 32rpx;
	}

	.h2 {
		font-size: 28rpx;
	}

	.h3 {
		font-size: 24rpx;
	}

	.h4 {
		font-size: 20rpx;
	}

	.h5 {
		font-size: 16rpx;
	}

	.h6 {
		font-size: 12rpx;
	}

	.red {
		color: #E2231A;
	}

	.huaxianjia {
		text-decoration: line-through;
		color: #585858;
		margin-left: 5rpx;
	}

	.acttention {
		width: 100%;
		background-color: #f2f2f2;
	}

	.acttention-item {
		margin: 20rpx;
		background-color: #fff;
		border-radius: 15rpx;
		margin-top: 24rpx;
		display: flex;
		align-items: center;
		padding: 24rpx;
		box-sizing: border-box;
		position: relative;
	}

	.acttention-item .item-image {
		width: 152rpx;
		height: 152rpx;
		margin-right: 17rpx;
		display: block;
	}

	.item-info {
		flex: 1;
		height: 152rpx;
		display: flex;
		justify-content: space-between;
		flex-direction: column;
		box-sizing: border-box;
	}

	.item-title {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		text-overflow: ellipsis;
		-webkit-box-orient: vertical;
		word-wrap: break-word;
		word-break: break-all;
		overflow: hidden;
	}

	.item-price {
		display: flex;
		align-items: flex-end;
		justify-content: flex-end;
	}

	.item-sales {
		color: #585858;
	}

	.acttention-item .item-btn {
		font-size: 28rpx;
		width: 182rpx;
		height: 56rpx;
		line-height: 56rpx;
		padding: 0;
		padding: 0;
		border-radius: 56rpx;
		box-sizing: border-box;
	}
</style>